package no.sachmuld.methodcombination.examples.annotation.combo.courier;

import no.sachmuld.methodcombination.api.*;
import no.sachmuld.methodcombination.api.annotation.MethodCombinationException;
import no.sachmuld.methodcombination.api.annotation.UsesMethodCombination;
import no.sachmuld.methodcombination.examples.annotation.combo.ContractChecking;
import no.sachmuld.methodcombination.examples.annotation.combo.StandardCrosscutting;

/**
 *
 */
@UsesMethodCombination(CourierBehaviour.class)
public class Courier extends MethodCombinationSupport<CrosscuttingBehaviour> {

    public Courier() {

        with(new CourierBehaviour() {

            @Override
            public Condition beforeDeliver(Package pkg, Context context) {
                return new Condition("package weight < 3", pkg.getWeightInKg() < 3);
            }

            @Override
            public Delivery deliver(Package pkg, MethodInvocation<Delivery> methodInvocation) {
                System.out.println("Courier.deliver");
                return new Delivery(6);
            }

            @Override
            public Condition afterDeliver(Package pkg, Delivery delivery, Context context) {
                return new Condition("delivery time < 8", delivery.getDeliveryTimeInHours() < 8);
            }

        });
    }

    @ContractChecking @StandardCrosscutting
    public final Delivery deliver(final Package pkg) {
        throw new MethodCombinationException();
    }

    @Override
    public Courier with(CrosscuttingBehaviour... behaviours) {
        super.with(behaviours);
        return this;
    }
}
